package br.com.beethoven.model.fachada.impl;

import br.com.beethoven.model.entidade.vo.MusicaVO;
import java.util.List;
import java.sql.ResultSet;
import br.com.beethoven.exception.BDException;
import br.com.beethoven.model.entidade.vo.CD_VO;
import br.com.beethoven.model.fachada.IGerenciarCdFacade;
import br.com.beethoven.model.service.ServiceGerenciarCD;
import java.util.LinkedList;

public class GerenciarCdFacade implements IGerenciarCdFacade {
        private java.sql.Connection conexao;

	@Override
	public void cadastrar(CD_VO cd_VO) throws BDException {
		ServiceGerenciarCD gerenciarCD = new ServiceGerenciarCD();
		gerenciarCD.cadastrar(cd_VO);
	}

	@Override
	public void editar(CD_VO cd_VO) throws BDException {
		ServiceGerenciarCD gerenciarCD = new ServiceGerenciarCD();
		gerenciarCD.editar(cd_VO);
	}

	@Override
	public void remover(CD_VO cd_VO) throws BDException {
		ServiceGerenciarCD gerenciarCD = new ServiceGerenciarCD();
		gerenciarCD.remover(cd_VO);
	}

	@Override
	public List<CD_VO> listar() throws BDException {
		ServiceGerenciarCD gerenciarCD = new ServiceGerenciarCD();
		return gerenciarCD.listar();
	}

    public List<MusicaVO> getMinhasMusicas(CD_VO _cd) {
        List<MusicaVO> listaMusicas = new LinkedList<MusicaVO>();
            String comando = "select * from musica where id_cd = '"+_cd.getId()+"';";
            try{

			Class.forName("org.gjt.mm.mysql.Driver");
			conexao = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/beethoven", "root", "hehehe");

                        java.sql.Statement start = conexao.createStatement();
			ResultSet rs = start.executeQuery(comando);

			while(rs.next()){
				MusicaVO musica = new MusicaVO();

				int idMusica = Integer.parseInt(rs.getString("id"));

				musica.setId(idMusica);
				musica.setNome(rs.getString("nome"));

				listaMusicas.add(musica);
			}
                        conexao.close();
		}catch (Exception e) {
			System.out.println("essa budega nao conectou!!!!");
		}


            return listaMusicas;
    }

}
